package graphics.raytracing;

import graphics.datastructures.Model;
import static util.MatrixOperationsF.*;
import java.util.Collection;

public class ShadedRay implements Ray{
	private int _x;
	private int _y;
	private Collection<LightSource> lightSources;
	private Model model;
	private RayRunner runner;
	private float[] _origin;
	private float[] _direction;
	
	public ShadedRay(Tracable trace, Window window,float[] origin,float[] direction) {
		_origin = origin;
		_direction=direction;
		
	}
	@Override
	public boolean canBeCast() {
		return false;
	}
	@Override
	public float[] getOrigin() {
		return _origin
				;
	}
	@Override
	public float[] getDirection() {
		return _direction;
	}
	@Override
	public Ray setRunner(RayRunner runner) {
		this.runner=runner;
		return this;
	}
	@Override
	public void makeRay(final Model trace, final Window window) {
		runner.registerRay(new Runnable() {
			@Override
			public void run() {
				CastResult result =model.cast(ShadedRay.this);
				if(result==null)
					window.color(_x, _y, ar(0,0,0));
				for(LightSource source:lightSources)
					for(Ray ray: source.createRays(result.getLocation()))
						ray.setRunner(runner);
			}
		});
	}
}
